package com.blt.car.me;

import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.baidu.platform.comapi.map.B;
import com.blt.car.R;
import com.blt.car.base.BaseTitleBarActivity;
import com.blt.car.base.ViewHolder;
import com.blt.car.me.adapter.BillDetailAdapter;
import com.blt.car.utils.StringUtils;

import blt.app_core.api.base.CoreEvent;
import blt.app_core.api.base.CoreManager;
import blt.app_core.api.invoce.InvoiceApi;
import blt.app_core.api.invoce.InvoiceVo;

/**
 * Created by xgp on 2017/6/20.
 */

public class BillDetailActivity extends BaseTitleBarActivity {

    public static final String BILL_ID = "bill_id";

    private TextView tvCompany;
    private TextView tvAmount;
    private TextView tvContent;
    private TextView tvRecevier;
    private TextView tvAddress;
    private TextView tvPhone;
    private TextView tvTime;
    private TextView tvReply;
    private TextView tvStatus;

    private ListView mListView;
    private BillDetailAdapter detailAdapter;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_bill_detail;
    }

    @Override
    protected void initData() {
        super.initData();
        int id = getIntent().getExtras().getInt(BILL_ID);
        CoreManager.getCore(InvoiceApi.class).getInvoiceDetail(id);
    }

    @Override
    protected void initView(ViewHolder holder) {
        mTitleBar.setTitle("发票详情");
        tvCompany = holder.get(R.id.bill_detail_company);
        tvAmount = holder.get(R.id.bill_detail_amount);
        tvContent = holder.get(R.id.bill_detail_content);
        tvRecevier = holder.get(R.id.bill_detail_receiver);
        tvPhone = holder.get(R.id.bill_detail_phone);
        tvAddress = holder.get(R.id.bill_detail_address);
        tvReply = holder.get(R.id.bill_detail_reply);
        tvStatus = holder.get(R.id.bill_detail_status);
        tvTime = holder.get(R.id.bill_detail_day);

        mListView = holder.get(R.id.bill_detail_listview);
        mListView.setEnabled(false);
        detailAdapter = new BillDetailAdapter(this);
        mListView.setAdapter(detailAdapter);
    }

    @CoreEvent(coreClientClass = InvoiceApi.class)
    public void onInvoiceDetail(InvoiceVo vo) {
        tvCompany.setText(vo.company);
        int index = vo.amount.indexOf(".");
        String account = vo.amount.substring(0, index);
        tvAmount.setText(account + "元");
        tvContent.setText(vo.content);
        tvRecevier.setText(vo.contactUser);
        tvPhone.setText(vo.contactPhone);
        tvAddress.setText(vo.contactAddress);
        tvTime.setText(StringUtils.getHanZiDay(vo.applyTime));
        tvReply.setText(vo.reply);

        if (vo.type == 0) {
            tvContent.setVisibility(View.GONE);
            tvRecevier.setVisibility(View.GONE);
            tvPhone.setVisibility(View.GONE);
        }

        if (vo.status == 0) {
            tvStatus.setText("未处理");
        } else if (vo.status == 1) {
            tvStatus.setText("已受理");
        } else if (vo.status == 2) {
            tvStatus.setText("已拒绝");
        }
        detailAdapter.add(vo.travelOrderList);
    }
}
